package net.maxwoods.servlet;

import net.maxwoods.listener.MyWriteListener;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Servlet implementation class MyServlet2
 */
@WebServlet("/MyServlet2")
public class MyServlet2 extends HttpServlet {

    private ServletConfig config;

    /**
     * @see Servlet#init(ServletConfig)
     */
    public void init(ServletConfig config) throws ServletException {
        this.config = config;
    }


    /**
     * @see Servlet#getServletConfig()
     */
    public ServletConfig getServletConfig() {

        return config;
    }


    public String getServletInfo() {

        return "My Servlet2";
    }

    @Override
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {

        PrintWriter pw = response.getWriter();
        pw.print(config.getServletName());
        super.service(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //response.getOutputStream().setWriteListener(new MyWriteListener());
        PrintWriter pw = response.getWriter();
        pw.print("Max Woods");
    }
}
